package org.lsc.summercontroller;

import org.lsc.summerentity.ResultVo;
import org.lsc.summerservice.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/** * @author 刘事成

 * @Description:
 * @date 2018/9/13 11:35
 */
@RestController
@RequestMapping("/user")
public class UserController {

    //证明构造器>@Autowired>@PostConstruct(加载顺序)
    @PostConstruct
    public void init(){
        if ( null != userService ) {
            System.out.println("userService存在");
        }
        System.out.println("init");
    }

    @Autowired
    UserService userService;

    public UserController(){
        if ( null != userService ) {
            System.out.println("userService存在");
        }
        System.out.println("UserController构造");
    }

    @GetMapping("list")
    public ResultVo list() {
        try {
            System.out.println("list");
            return ResultVo.isOk().data(userService.list());
        } catch (Exception e) {
            return ResultVo.isFail(e);
        }

    }

}